package com.bus.stream

import java.sql.{Connection, Date, DriverManager, PreparedStatement}

object MySQLUtil {

  def getConnection() = {
    Class.forName("com.mysql.cj.jdbc.Driver")
    DriverManager.getConnection("jdbc:mysql://106.13.32.254:3306/febs_st_bus?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false", "st_bus", "123456")
  }

  def closeConnection(con: Connection): Unit = {
    if (con != null) {
      con.close()
    }
  }

  def release(con: Connection, state: PreparedStatement): Unit = {
    try {
      if (state != null) {
        state.close()
      }
    } catch {
      case e: Exception => e.printStackTrace()
    } finally {
      if (con != null) {
        con.close()
      }
    }
  }
}
